﻿using BattleFury.Lib.ServerPlayer;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace BattleFuryGameEngine.GameData
{
    public class GenericPlayerCollection
    {
        private Dictionary<long, GenericPlayer> _playerCollection = new Dictionary<long, GenericPlayer>();
        public Dictionary<long, GenericPlayer> PlayerCollection
        {
            get
            {
                return _playerCollection;
            }
        }

        public bool Contains(long id)
        {
            return _playerCollection.ContainsKey(id);
        }
        public GenericPlayer Get(long id)
        {
            GenericPlayer _t;
            if (_playerCollection.TryGetValue(id, out _t))
                return _t;
            throw new Exception("Player not found: " + id);
        }

        public GenericPlayer AddPlayer(long newPlayer)
        {
            if (!_playerCollection.ContainsKey(newPlayer))
            {
                Random r = new Random();
                int xxx = r.Next(500, 500);
                GenericPlayer genPlayer = new GenericPlayer(newPlayer);
                if (newPlayer == 2)
                {
                    genPlayer.Position = new Vector2(xxx, xxx);
                    genPlayer.Size = new Vector2(32f, 32f);
                }
                else
                {
                    genPlayer.Position = new Vector2(1000, 0);
                    genPlayer.Size = new Vector2(32f, 32f);
                }
                _playerCollection.Add(newPlayer, genPlayer);
                return genPlayer;
            }
            return null;
        }

        public int Count { get { return _playerCollection.Count; } }

        internal void RemovePlayer(long tempPlayer)
        {
            _playerCollection.Remove(tempPlayer);
        }
    }
}
